﻿using Common.Events;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;

namespace ModuleComomn.ViewModels
{
    public class TFreezableViewModel : BindableBase
    {

        private bool hasName;
        public bool HasName
        {
            get { return hasName; }
            set { SetProperty(ref hasName, value); }
        }


        public ObservableCollection<Person> PersonList { get; set; }

        public ICommand ShowNameCommand { get; set; }

        public TFreezableViewModel(IEventAggregator eventAggregator)
        {
            PersonList = new ObservableCollection<Person>();
            PersonList.Add(new Person() { Name = "A", Age = 1 });
            PersonList.Add(new Person() { Name = "B", Age = 2 });

            ShowNameCommand = new DelegateCommand<Person>(async p => {
                System.Diagnostics.Debug.WriteLine($"ShowNameCommand：{p.Name}");
                await Task.Delay(3000);
                eventAggregator.GetEvent<MessageNotyifyEvent>().Publish($"ShowNameCommand：{p.Name}");
            });
        }

        public class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }
    }

}
